// 将数据存到浏览器中
var loginr = JSON.stringify(login);
localStorage.setItem("loginArr", loginr);

var cityArrr = JSON.stringify(cityArr);
localStorage.setItem("cityArr", cityArrr);

var schoolArrr = JSON.stringify(schoolArr);
localStorage.setItem("schoolArr", schoolArrr);

var activeArrr = JSON.stringify(activeArr);
localStorage.setItem("activeArr", activeArrr);

var studentArrr = JSON.stringify(studentArr);
localStorage.setItem("studentArr", studentArrr);

var classArrr = JSON.stringify(classArr);
localStorage.setItem("classArr", classArrr);

var employeeArrr = JSON.stringify(employeeArr);
localStorage.setItem("employeeArr", employeeArrr);

var depArrr = JSON.stringify(depArr);
localStorage.setItem("depArr", depArrr);

var posArrr = JSON.stringify(posArr);
localStorage.setItem("posArr", posArrr);

var politicalArrr = JSON.stringify(politicalArr);
localStorage.setItem("politicalArr", politicalArrr);

var cultureArrr = JSON.stringify(cultureArr);
localStorage.setItem("cultureArr", cultureArrr);

var communicationr = JSON.stringify(communication);
localStorage.setItem("communication", communicationr);


/* var studentsStr = localStorage.getItem("communication");
var communication = JSON.parse(studentsStr);
console.log(communication);
var a = {
    comId: 1, //沟通记录id
    schoolid: 1, //学校id
    comTime: '2010-08-09', //校方联系人
    comXiaofang: '朱子明', //校方联系人
    comPos: '校长', //职务
    comWofang: '张三', //沟通人
    comNeirong: '邀请加入系统', //沟通内容
};
communication.push(a)
console.log(communication);
var communicationr = JSON.stringify(communication);
localStorage.setItem("communication", communicationr); */


$('.mb2').click(Login);

function Login() {
    var username = document.getElementById("ID").value;
    var password = document.getElementById("PASSWORD").value;
    if (username == "") {
        $.jGrowl("用户名不能为空！", { header: '提醒' });
        return false;
    } else if (password == "") {
        $.jGrowl("密码不能为空！", { header: '提醒' });
        return false;
    } else if (!$('.gly')[0].checked && !$('.ls')[0].checked) {
        $.jGrowl("请选择身份！", { header: '提醒' });
        return false;
    } else {
        AjaxFunc();
        return true;
    }
}

function AjaxFunc() {
    var Username = $('.Username')[0].value;
    var Pwd = $('.pwd')[0].value;

    var Identity = null;
    if ($('.gly')[0].checked) {
        Identity = 1;
    } else if ($('.ls')[0].checked) {
        Identity = 2;
    }
    var login = localStorage.getItem("loginArr");
    var loginArr = JSON.parse(login);
    console.log(Username, Pwd, Identity);
    // 管理员登录
    for (var i = 0; i < loginArr.length; i++) {
        if (Username == loginArr[i].account && Pwd == loginArr[i].pwd && Identity == loginArr[i].Identity) {
            // 将登录时的账号，密码，身份存储的浏览器中
            sessionStorage.setItem('account', Username);
            sessionStorage.setItem('Name', loginArr[i].Name);
            sessionStorage.setItem('pwd', Pwd);
            sessionStorage.setItem('Identity', Identity);
            window.open('html/c_index.html', '_self');
            // window.open('html/c_index.html');
            break;
        } else {
            $.jGrowl("账号或密码、身份不正确！", { header: '提醒' });
        }
    }
}